<html>

	<head>
		<meta charset="UTF-8">
		<title>LNG气量平衡报表</title>
		<meta name="renderer" content="webkit">
		<meta http-equiv="X-UA-Compatible" content="IE=edge,chrome=1">
		<link rel="stylesheet" href="../../layui/css/layui.css" />
		<link rel="stylesheet" href="../../css/bass.css" />
	</head>

	<body>
		<div class="body">
			<header class="layui-nav" id="headerTop"></header>
			<div class="left_muen" id="left_menu"></div>
			<div class="content_body">

				<!--标题栏-->
				<p class="content_title">数据监控 &nbsp;&nbsp;>&nbsp;&nbsp;LNG气量平衡报表</p>
				<!--标题栏-->

				<!--条件查询-->
				<div class="content_seach">
					<div class="layui-form">
						<div class="layui-form-item">
							<div class="layui-inline">
								<label class="layui-form-label">日期</label>
								<div class="layui-input-inline ml10">
									<input type="text" name="" id="dateStart" lay-verify="date" placeholder="请选择时间" autocomplete="off" class="layui-input">
								</div>
								<div class="layui-form-mid"></div>
								<div class="layui-input-inline ml10">
									<input type="text" name="" id="dateEnd" placeholder="请选择时间" autocomplete="off" class="layui-input">
								</div>
							</div>
							<div class="layui-inline">
								<div class="layui-input-inline" style="width:300px;">
									<input type="radio" name="" value="0" title="标方">
									<input type="radio" name="" value="1" title="吉焦">
									<input type="radio" name="" value="1" title="吨">
								</div>
							</div>
							<button class="layui-btn layui-btn-warm search layui-btn-sm" id="search" lay-submit="" lay-filter="search"><i class="layui-icon">&#xe615;</i>查询</button>
						</div>
					</div>
				</div>
				<!--条件查询-->

				<!--表格-->
				<div class="content_table">
					<script type="text/html" id="toolbarDemo">
						<div class="layui-btn-container">
							<a class="layui-btn layui-btn-sm" id="configure"><i class="layui-icon">&#xe620;</i> 配置</a>
							<a class="layui-btn layui-btn-sm"><i class="layui-icon">&#xe62c;</i> 趋势图</a>
						</div>
					</script>
					<div class="tabTable">
						<table id="table" lay-filter="tableFilter"></table>
						<div class="layui-table-page fr">
							<div id="layui-table-page1"></div>
						</div>
					</div>
				</div>
				<!--表格-->
			</div>

		</div>
		<script src="../../js/common/jquery-1.11.3.min.js"></script>
		<script src="../../layui/layui.js"></script>
		<script src="../../js/common/navList.js"></script>
		<script src="../../js/common/ajax.js"></script>
		<script type="text/html" id="inputStandardConditionSumColor">
			{{# if(d.inputStandardConditionSum > 0.05){ }}
			<span style="color: red;">{{ d.inputStandardConditionSum }}</span> {{# } }}
		</script>
		<script>
			layui.use(['table', 'laydate', 'form'], function() {
				var table = layui.table,
					form = layui.form,
					laydate = layui.laydate;

				laydate.render({
					elem: '#dateStart',
					type: 'date'
				});
				laydate.render({
					elem: '#dateEnd',
					type: 'time',
					range: true
				});

				$.ajax({
					url: baseUrl + 'monitordata/getSiteConfigList',
					type: 'GET',
					dataType: 'json',
					async: false,
					data: {
						reportIndex: 7, //LNG气量平衡报表
						pageNo: 1,
						groupType: 1 //1-按天 2-按周 3-按月 4-按年
					},
					traditional: true,
					timeout: 30000,
					success: function(res) {
						console.log(res);
						var dataCols = [{
								field: 'date',
								title: '时间',
								align: 'center'
							},
							{
								field: 'weather',
								title: '天气情况',
								align: 'center',
								templet: function(d) {
									//									console.log(d);
									if(d.list.length != 0) {
										for(var i = 0; i < d.list.length; i++) {
											if(d.list[0].weather == '' || d.list[0].weather == null || d.list[0].weather == undefined) {
												return '<div>-</div>';
											} else {
												return '<div>' + d.list[i].weather + '°c</div>';
											}
										}
									} else {
										return '<div>-</div>';
									}
								}
							},
						];
						var siteNames = '';
						$.each(res, function(j, item) {
							dataCols.push({
								field: 'list',
								title: item.siteName,
								align: 'center',
								templet: function(d) {
									if(d.list.length != 0) {
										for(var i = 0; i < d.list.length; i++) {
												if(d.list[i].wastageRate == null) {
													d.list[i].wastageRate = '0';
												};
												if(d.list[i].wastageRate > 5) {
													return '<div class="wastageRate" style="color:red;" siteName=' + d.list[i].siteName + ' dates=' + d.date + '>' + d.list[i].wastageRate + '%</div>';
												} else {
													return '<div class="wastageRate" siteName=' + d.list[i].siteName + ' dates=' + d.date + '>' + d.list[i].wastageRate + '%</div>';
												}
											}
									} else {
										return '<div>-</div>';
									}
								}
							});
							//																拼接下面传递的参数;
							if(j == res.length - 1) {
								console.log(11)
								siteNames += item.siteName
							} else {
								siteNames += item.siteName + ',';
							}
							//							siteNames += '&siteNames[]=' + item.siteName;

						});
						var startTimes = crtTimeFtt();
						ajaxTable({
							idNode: '#table',
							page: true,
							url: 'monitordata/getListAll',
							urlParme: '&groupType=1&siteNames=' + siteNames + '&startTime=' + startTimes + '+00:00&endTime=' + startTimes + '+23:59',
							dataCols: dataCols,
							successFull: function(res, curr, count) {
								// console.log(res)
							}
						})
					}
				})

				//条件查询
				form.on('submit(search)', function(data) {
					var startTime = $("#dateStart").val();
					var endTime = $("#dateEnd").val()
					console.log(startTime);
					console.log(endTime);
					if(endTime == "") {
						layer.msg("请选择结束时间", {
							icon: 5
						});
						return;
					};
					var urlParme = "&groupType=1";
					if(startTime != null && startTime != "" && startTime != undefined && endTime != null && endTime != "" && endTime != undefined) {
						var houers = endTime.split("-");
						endTime = startTime + "+" + $.trim(houers[1]);
						startTime = startTime + "+" + $.trim(houers[0]);
						urlParme += "&startTime=" + startTime + "&endTime=" + endTime;
					};
					$.ajax({
						url: baseUrl + 'monitordata/getSiteConfigList',
						type: 'GET',
						dataType: 'json',
						async: false,
						data: {
							reportIndex: 7, //LNG气量平衡报表
							pageNo: 1,
							groupType: 1 //1-按天 2-按周 3-按月 4-按年
						},
						traditional: true,
						timeout: 30000,
						success: function(res) {
							console.log(res);
							var dataCols = [{
									field: 'date',
									title: '时间',
									align: 'center'
								},
								{
									field: 'weather',
									title: '天气情况',
									align: 'center',
									templet: function(d) {
										//									console.log(d);
										if(d.list.length != 0) {

											for(var i = 0; i < d.list.length; i++) {
												if(d.list[0].weather == '' || d.list[0].weather == null || d.list[0].weather == undefined) {
													return '<div>-</div>';
												} else {
													return '<div>' + d.list[i].weather + '°c</div>';
												}
											}
										} else {
											return '<div>-</div>';
										}
									}
								},
							];
							var siteNames = '';
							$.each(res, function(j, item) {
								dataCols.push({
									field: 'list',
									title: item.siteName,
									align: 'center',
									templet: function(d) {
										console.log(i);
										if(d.list.length != 0) {
											for(var i = 0; i < d.list.length; i++) {
												if(d.list[i].wastageRate == null) {
													d.list[i].wastageRate = '0';
												};
												if(d.list[i].wastageRate > 5) {
													return '<div class="wastageRate" style="color:red;" siteName=' + d.list[i].siteName + ' dates=' + d.date + '>' + d.list[i].wastageRate + '%</div>';
												} else {
													return '<div class="wastageRate" siteName=' + d.list[i].siteName + ' dates=' + d.date + '>' + d.list[i].wastageRate + '%</div>';
												}
											}
										} else {
											return '<div>-</div>';
										}
									}
								});
								//																	拼接下面传递的参数;
								if(j == res.length - 1) {
									console.log(11)
									siteNames += item.siteName;
								} else {
									siteNames += item.siteName + ',';
								}
							});
							urlParme = '&groupType=1&siteNames=' + siteNames + '&startTime=' + startTime + '&endTime=' + endTime;
							ajaxTable({
								idNode: '#table',
								page: true,
								url: 'monitordata/getListAll',
								urlParme: urlParme,
								dataCols: dataCols,
								successFull: function(res, curr, count) {
									// console.log(res)
								}
							})
						}
					})
				});

				//监听工具条
				table.on('tool(tableFilter)', function(obj) {
					var data = obj.data;
					if(obj.event === 'detail') {
						layer.msg('ID：' + data.id + ' 的查看操作');
					} else if(obj.event === 'del') {
						layer.confirm('确定删除吗？', function(index) {
							console.log(data);
							$.ajax({
								url: baseUrl + "/user/del",
								type: "POST",
								data: {
									"id": data.id
								},
								dataType: "json",
								success: function(data) {
									if(data.code == 200) {
										obj.del();
										layer.close(index);
										layer.msg("删除成功", {
											icon: 6
										});
									} else {
										layer.msg("删除失败", {
											icon: 5
										});
									}
								}
							});
						});
					} else if(obj.event === 'edit') {
						layer.confirm('确定修改吗？', function(index) {
							location.href = "./adminEdit.html?pos=3&childPos=0&id=" + data.id;
						});
					}
				});

				/* 配置 */
				$("#configure").click(function() {
					/* 再弹出添加界面 */
					layer.open({
						type: 2,
						title: "配置",
						skin: "myclass",
						area: ["720", '470'],
						content: 'configure.html?reportIndex=7',
					});
					return false;
				});

				//				点击供输差跳转至详情页面
				$("body").on('click', '.wastageRate', function() {
					//					截取当前路径参数   获取当前活跃选项卡
					//					console.log(111);
					//					拼接页面所需的参数
					var jumphref = window.location.href;
					console.log(jumphref);
					var pos = jumphref.split("?")[1].split("&")[0].split("=")[1];
					var childPos = jumphref.split("?")[1].split("&")[1].split("=")[1];
					var siteName = $(this).attr("siteName");
					var time = $(this).attr("dates");
					window.location.href = "./detailsReportList.html?pos=" + pos + "&childPos=" + childPos + "&reportIndex=7&siteName=" + siteName + "&time=" + time;
				})

			});
		</script>
	</body>

</html>